package com.crscd.ai.controller;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 9/29/25 2:30 PM
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
public class ChatHelloController {
  @Autowired private ChatModel chatModel;

  /**
   * 通用调用
   *
   * @param msg the msg
   * @return the string
   */
  @GetMapping("/hello/doChat")
  public String doChat(@RequestParam(value = "msg", defaultValue = "你是谁") String msg) {
    return chatModel.call(msg);
  }

  /**
   * 流式响应
   *
   * @param msg the msg
   * @return the flux
   */
  @GetMapping("/hello/streamChat")
  public Flux<String> stream(@RequestParam(value = "msg", defaultValue = "你是谁") String msg) {
    return chatModel.stream(msg);
  }
}
